package cn.qiao.fs.event;


import cn.qiao.cc.event.Event;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class FsEventManager implements ApplicationContextAware {

    private final Map<String, FsEvent> handlerMap = new HashMap<>();

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, FsEvent> beans = applicationContext.getBeansOfType(FsEvent.class);
        beans.forEach((k, v) -> {
            handlerMap.put(v.type(), v);
        });
    }

    public FsEvent getEventHandler(String type){
        return handlerMap.get(type);
    }

}